//
//  PasswordController.m
//  i5db
//
//  Created by iMuse on 15-5-19.
//  Copyright (c) 2015年 mySelf. All rights reserved.
//

#import "PasswordController.h"
#import "AppDelegate.h"
#import "AppCenter.h"
@interface PasswordController ()
{
    UITextField * passwordLabel ;
    UITextField * surePasswordLabel;
    UILabel     * line;
    UIButton    * loginButton;
}

@end

@implementation PasswordController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
      self.title = @"设置密码";
    }
    return self;
}

-(void)updateViewConstraints
{
    [super updateViewConstraints];
    
    [passwordLabel autoPinToTopLayoutGuideOfViewController:self withInset:10];
    [passwordLabel autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:0];
    [passwordLabel autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:0];
    [passwordLabel autoSetDimension:ALDimensionHeight toSize:45];
    
    [line autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:passwordLabel withOffset:0];
    [line autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:0];
    [line autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:0];
    [line autoSetDimension:ALDimensionHeight toSize:0.5];
    
    [surePasswordLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:line withOffset:0];
    [surePasswordLabel autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:0];
    [surePasswordLabel autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:0];
    [surePasswordLabel autoSetDimension:ALDimensionHeight toSize:45];
    
    
    [loginButton autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:surePasswordLabel withOffset:10];
    [loginButton autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:20];
    [loginButton autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:20];
    [loginButton autoSetDimension:ALDimensionHeight toSize:40];
}
-(void) initNavigationBar{
    [super initNavigationBar];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view setNeedsUpdateConstraints];
    [self initNavigationBar];
    [self initView];
    
}
-(void) initView
{
    
    passwordLabel = [UITextField newAutoLayoutView];
    passwordLabel.textAlignment = NSTextAlignmentCenter;
    passwordLabel.clearButtonMode = UITextFieldViewModeWhileEditing;
    passwordLabel.placeholder = @"密码";
    passwordLabel.secureTextEntry = YES;
    passwordLabel.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:passwordLabel];
    line = [UILabel newAutoLayoutView];
    line.backgroundColor = [AppCenter color:@"188,188,188,1"];
    [self.view addSubview:line];
    
    surePasswordLabel = [UITextField newAutoLayoutView];
    surePasswordLabel.secureTextEntry = YES;
    surePasswordLabel.clearButtonMode = UITextFieldViewModeWhileEditing;
    surePasswordLabel.placeholder = @"确认密码";
    surePasswordLabel.textAlignment = NSTextAlignmentCenter;
    surePasswordLabel.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:surePasswordLabel];
    
    [self performSelector:@selector(textResponder) withObject:nil afterDelay:0];
    
    loginButton = [UIButton newAutoLayoutView];
    loginButton.layer.borderWidth = 1;
    loginButton.layer.cornerRadius = 4;
    loginButton.layer.borderColor = [AppCenter color:@"76,187,248,1"].CGColor;
    [loginButton setTitleColor:[AppCenter color:@"76,187,248,1"] forState:UIControlStateNormal];
    [loginButton setTitle:@"登录" forState:UIControlStateNormal];
    [loginButton addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:loginButton];
}

-(void)login
{
    AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
	[appDelegate showTabBar];
    [self.navigationController popToRootViewControllerAnimated:NO];
}

-(void)textResponder
{
    [passwordLabel becomeFirstResponder];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    
}


@end
